package b1.scenes.home
{
	import b1.controls.basic.*;
	import b1.net.*;
	import b1.scenes.*;
	
	import flash.display.Sprite;
	import flash.events.*;
	import flash.text.*;

	public class AddressNavigator extends Sprite
	{
		public var numBox:TextField;
		public static const baseLiveNum:int = 31455926;
		private var addressNavigatorTip:BasicMessage;
		private var goButtonTip:BasicMessage;
		 
		public function AddressNavigator(liveId:int)
		{
			super();
			//地址门牌背景
			var AddressNavigatorBgr:Class = ResourceHelper.getInstance().getClassByName("AddressNavigatorBgr");
			addChild(new AddressNavigatorBgr());
			//数字输入框
			numBox = new TextField();
			numBox.defaultTextFormat = new TextFormat("微软雅黑", 15, 0x000000, true);
			numBox.restrict = "0-9";
			numBox.width = 88;
			numBox.height = 20;
			numBox.x = 16;
			numBox.y = 6;
			numBox.type = TextFieldType.INPUT;
			numBox.text = (liveId + baseLiveNum).toString();
//			numBox.background = true;
			addChild(numBox);
			//跳转按钮
			var AddressNavigatorGo:Class = ResourceHelper.getInstance().getClassByName("AddressNavigatorGo");
			var goButton:BasicButton = new BasicButton(AddressNavigatorGo);
			goButton.x = this.width - 58;
			goButton.y = 7;
			goButton.addEventListener(MouseEvent.CLICK, onGoButtonClick);
			addChild(goButton);
//			goButton.addEventListener(MouseEvent.MOUSE_OVER, goButtonOnMouseOver);
//			goButton.addEventListener(MouseEvent.MOUSE_OUT, goButtonOnMouseOut);
			
			this.addEventListener(MouseEvent.MOUSE_OVER, onMouseOver);
			this.addEventListener(MouseEvent.MOUSE_OUT, onMouseOut);
		}
		
		private function onGoButtonClick(event:MouseEvent):void
		{
			if (SceneContainer.getInstance().mouseDisableFlag && !SceneContainer.getInstance().checkOnlyMousePosition(event.currentTarget))
				return;
			var liveId:int = parseInt(numBox.text) - baseLiveNum;
			if (liveId >= 0)
			{
				var home:Home = SceneContainer.getInstance().currentScene as Home;
				home.switchLiveId(liveId);
			}
		}
		
		private function goButtonOnMouseOver(event:MouseEvent):void
		{
			var tipString:String = "单击跳转";
			goButtonTip = new BasicMessage(tipString.length * 20, 25, tipString);
			goButtonTip.x = this.width;
			addChild(goButtonTip);
		}
		
		private function goButtonOnMouseOut(event:MouseEvent):void
		{
			if (null !=  goButtonTip && null != goButtonTip.parent)
        	{
        		goButtonTip.parent.removeChild(goButtonTip);
        	}
		}
		
		private function onMouseOver(event:MouseEvent):void
		{
			var string:String = "输入门牌号，跳转";
			addressNavigatorTip = new BasicMessage(string.length * 18, 25, string);
			addressNavigatorTip.y = this.height + 5;
			addressNavigatorTip.x = (this.width - addressNavigatorTip.width) / 2;
			addChild(addressNavigatorTip);
		}
		
		private function onMouseOut(event:MouseEvent):void
		{
			if (null !=  addressNavigatorTip && null != addressNavigatorTip.parent)
        	{
        		addressNavigatorTip.parent.removeChild(addressNavigatorTip);
        	}
		}
	}
}